# 做容错处理：代码会非常多(只是一种解决方案)
def funa(x,y):
    # print(x/y)这个就是可能会出错的代码
    if y == 0:
        print("除数不能为0")
    else:
        print(x/y)
funa(10,2)
funa(10,0)

# 捕获异常
"""
try:
    可能会出错的代码
except 异常类型:
    出错之后进行处理
"""
def funa(x,y):
    try:  # 进行检测
        print(x/y)
    except ZeroDivisionError:  # 异常的捕获
        print("除数不能为0")

# funa(10,0)
funa(10,2)

# 取别名  as
try:
    print(10 / 0)
except ZeroDivisionError as z:  # 拿到错误信息
    print(z)

# 写多个expect
try:
    print(a)  # NameError
except ZeroDivisionError:
    print("这是除零异常")
except NameError:
    print("这是名称异常")

# 捕获所有异常(万能异常)
try:
    print(a)
    # print(10/0)
except Exception as e:
    print(e)



